from fastapi import FastAPI, Response
from uuid import uuid1, uuid3, uuid4, uuid5, NAMESPACE_DNS

app = FastAPI()

@app.get("/uuid")
def get_uuid(version: int = 4):
    if version == 1:
        uid = str(uuid1())
    elif version == 3:
        uid = str(uuid3(NAMESPACE_DNS, 'cj.com'))
    elif version == 4:
        uid = str(uuid4())
    elif version == 5:
        uid = str(uuid5(NAMESPACE_DNS, 'cj.com'))
    else:
        return Response("Unsupported UUID version. Use 1, 3, 4, or 5.", media_type="text/plain", status_code=400)

    # 返回纯文本 UUID 字符串
    return Response(uid, media_type="text/plain")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)